<?php
/**
* http://fr.twitter.com/about/resources/tweetbutton
*/
class TwitterButton
{
	const DATACOUNT_HORIZONTAL = 'horizontal';
	const DATACOUNT_VERTICAL = 'vertical';
	const DATACOUNT_NONE = 'none';
	
	private $_dataCount = "horizontal"; //vertical, none
	private $_via = "theGridPaper";
	private $_button = "";
	private $_isDirty = TRUE;
	
	public function __construct($dataCount = "horizontal", $via = "theGridPaper")
	{
		$this->_dataCount = $dataCount;
		$this->_via = $via;
	}
	
	public function __set($name, $value)
	{
		if ($name == "dataCount" ||
			$name == "via")
			{
				$var = '_' . $name;
				$this->$var = $value;
				$this->_isDirty = TRUE;
			}
	}
	
	public function share()
	{
		if ($this->_isDirty)
		{
			$result = '<a href="http://twitter.com/share" class="twitter-share-button" ';
			$result .= 'data-count="' . $this->_dataCount . '"';
			$result .= 'data-via="' . $this->_via . '">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>';
			$this->_button = $result;
			$this->_isDirty = FALSE;
		}
		return $this->_button;
	}
	
	public function __tostring()
	{
		return $this->share();
	}
}
//
// $button = new TwitterButton();
// $button->dataCount = "vertical";
// $button->via = "twitter";
// echo (string)$button;

?>